﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ScenarioFramework.Portal.Modules.Menu;

namespace ScenarioFramework.Portal.SF.Forms.UserControls
{
    public partial class VerticalMenu : System.Web.UI.UserControl
    {
        public string Menu = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            MenuHelper menuHelper = (MenuHelper)Session["MenuHelper"];

            string[] vMenus = Menu.Split('/');

            ScenarioFramework.Portal.Modules.Menu.BO.Menu sfMenu = null;
            ScenarioFramework.Portal.Modules.Menu.BO.Menu[] menus = menuHelper.RootMenu.Menu;

            foreach (string sMenu in vMenus)
            {
                sfMenu = menuHelper.Get (menus, sMenu);
                menus = sfMenu.Menus;
            }

            if (sfMenu.Menus.Length == 0)
                return;

            PlaceHolder1.Controls.Add(new LiteralControl("<ul>"));
            foreach (ScenarioFramework.Portal.Modules.Menu.BO.Menu menu in sfMenu.Menus)
            {
                PlaceHolder1.Controls.Add(new LiteralControl("<li>"));
                PlaceHolder1.Controls.Add(new LiteralControl("<a href=\""));
                PlaceHolder1.Controls.Add(new LiteralControl(menu.Url));
                PlaceHolder1.Controls.Add(new LiteralControl("\">"));
                PlaceHolder1.Controls.Add(new LiteralControl("<span>"));
                PlaceHolder1.Controls.Add(new LiteralControl(menu.Name));
                PlaceHolder1.Controls.Add(new LiteralControl("</span>"));
                PlaceHolder1.Controls.Add(new LiteralControl("</a>"));

                PlaceHolder1.Controls.Add(new LiteralControl("</li>"));
            }

            PlaceHolder1.Controls.Add(new LiteralControl("</ul>"));
            PlaceHolder1.Controls.Add(new LiteralControl("</ul>"));
        }
    }
}